package news.yp.newsproject.utils;

import static news.yp.newsproject.MyApplication.appContext;

public class Utils {
    //根据手机分辨率从px转成dp
    public static int px2dp(int px) {
        float scale = appContext.getResources().getDisplayMetrics().density;
        return (int) (px / scale + 0.5f);
    }

    //根据手机分辨率从dp转成px
    public static int dip2px(int dpValue) {
        float scale = appContext.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
